<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
    <th:block th:include="include :: header('修改学习视频')"/>
    <th:block th:include="include :: bootstrap-fileinput-css"/>
</head>
<body class="white-bg">
<div class="wrapper wrapper-content animated fadeInRight ibox-content">
    <form class="form-horizontal m" id="form-videoInfo-edit" th:object="${videoInfo}">
        <input name="videoId" th:field="*{videoId}" type="hidden">
        <input name="videoUrl" th:field="*{videoUrl}" type="hidden">
        <div class="form-group">
            <label class="col-sm-3 control-label is-required">分类：</label>
            <div class="col-sm-8">
                <select name="classifyId" th:with="item=${@dict.selectVideoClassifyList()}" class="form-control">
                    <option th:each="dict : ${item}" th:text="${dict.classifyName}"
                            th:value="${dict.classifyId}" th:field="*{classifyId}"></option>
                </select>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label is-required">标题：</label>
            <div class="col-sm-8">
                <input name="title" th:field="*{title}" class="form-control" type="text" required>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label is-required">视频：</label>
            <div class="col-sm-8">
                <input class="file" id="videoFile" type="file" data-min-file-count="1"
                       data-theme="fas" accept=".mp4,.avi,.mov">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">状态：</label>
            <div class="col-sm-8">
                <div class="radio-box" th:each="dict : ${@dict.getType('sys_normal_disable')}">
                    <input type="radio" th:id="${'status_' + dict.dictCode}" name="status" th:value="${dict.dictValue}"
                           th:field="*{status}">
                    <label th:for="${'status_' + dict.dictCode}" th:text="${dict.dictLabel}"></label>
                </div>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">备注：</label>
            <div class="col-sm-8">
                <input name="remarks" th:field="*{remarks}" class="form-control" type="text">
            </div>
        </div>
    </form>
</div>
<th:block th:include="include :: footer"/>
<th:block th:include="include :: bootstrap-fileinput-js"/>
<script th:inline="javascript">
    var prefix = ctx + "web/videoInfo";
    $("#form-videoInfo-edit").validate({
        focusCleanup: true
    });
    function submitHandler() {
        if ($.validate.form()) {
            var formData = new FormData($("#form-videoInfo-edit")[0]);
            if ($('#videoFile')[0].files[0] != null) {
                formData.append('videoFile', $('#videoFile')[0].files[0]);
            }
            $.ajax({
                url: prefix + "/edit",
                type: 'post',
                cache: false,
                data: formData,
                processData: false,
                contentType: false,
                dataType: "json",
                success: function (result) {
                    $.operate.successCallback(result);
                }
            });
        }
    }

    $(function () {
        var j = document.getElementById('videoUrl').value;
        var videoArray = [];
        videoArray.push(ctx + j);
        $("#videoFile").fileinput('destroy');
        $("#videoFile").fileinput({
            uploadUrl: prefix + "/uploadVideo", //接受请求地址
            uploadAsync: true, //默认异步上传
            showUpload: false, //是否显示上传按钮,跟随文本框的那个
            showRemove: false, //显示移除按钮,跟随文本框的那个
            showCaption: true,//是否显示标题,就是那个文本框
            showPreview: true, //是否显示预览,不写默认为true
            dropZoneEnabled: false,//是否显示拖拽区域，默认不写为true，但是会占用很大区域
            language: 'zh', //设置语言
            dropZoneTitle: '请选择将要上传的视频',
            autoReplace: true,
            allowedFileExtensions: ["mp4", "avi", "mov"],
            maxFileSize: 204800,
            minFileCount: 1,
            maxFileCount: 1,
            previewFileType: ['video'],
            elCaptionText: ['请选择视频'],
            browseClass: "btn btn-primary",//按钮样式
            fileType: "any",
            allowedPreviewTypes: ['video'],
            previewFileIcon: "<i class='glyphicon glyphicon-king'></i>",
            msgFilesTooMany: "选择上传的文件数量({n}) 超过允许的最大数值{m}！",
            initialPreviewAsData: true,
            initialPreviewFileType: 'video',
            initialPreview: videoArray,
            initialPreviewConfig: [ //回显类型配置(重要)
                {
                    type: "video",
                    filetype: 'video/mp4'
                }
            ]
        })
    })
</script>
</body>
</html>